home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
DICOPY.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-15
|
4KB
|
151 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: dicopy.c
// Title: Data File I/O Library
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains code to update a logical file within a physical file.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <di.h>
//----------------------------------------------------------------------------
// Description: Update the data area of a logical file.
// Parameters: pcszP1 Physical file name to copy to.
// pcszL1 Logical file to copy to
// pcszP2 Physical file name to copy to.
// pcszL2 Logical file to copy from
// usType Logical file type
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioCopy(PCSZ pcszP1, PCSZ pcszL1, PCSZ pcszP2, PCSZ pcszL2, USHORT usType)
{
HPF hpf2 = -1, hpf1 = -1;
HLF hlf2 = -1, hlf1 = -1;
HF hf1, hf2;
BOOL fUser2, fUser1;
FPOS flen2;
BOOL fResult = FALSE;
BYTE bUser[MAX_DATA_USER];
FLAG32 fl;
USHORT usVersion;
if (HIUSHORT(pcszP2))
{
if (!DioOpenPhysical(pcszP2, &hpf2, TRUE))
goto ERROR_EXIT;
fUser2 = FALSE;
}
else
{
hpf2 = LOUSHORT(pcszP2);
Assert(hpf2 >= 0 && hpf2 < MAX_PHYSICAL_FILES);
Assert(di.physical[hpf2].fUsed);
fUser2 = TRUE;
}
// Not open logical file
if (!DioOpenLogical(pcszL2, &hlf2, usType))
goto ERROR_EXIT;
hf2 = di.logical[hlf2].hf;
flen2 = di.logical[hlf2].flen;
if ((flen2 % (FPOS)sizeof(DATAHDR)) != 0)
{
flen2 += sizeof(DATAHDR); // Round up to nearest multiple of
flen2 /= sizeof(DATAHDR); // header size
flen2 *= sizeof(DATAHDR);
}
if (!DioAppend(pcszP1, pcszL1, usType, di.logical[hlf2].usBlockSize, &hf1, NULL))
{
DioAppendClose(fResult, FALSE);
goto ERROR_EXIT;
}
if (!FileCopy(hf1, -1, hf2, di.logical[hlf2].fbase, flen2))
{
DioAppendClose(fResult, FALSE);
goto ERROR_EXIT;
}
if (!DioAppendClose(TRUE, TRUE))
goto ERROR_EXIT;
if (HIUSHORT(pcszP1))
{
if (!DioOpenPhysical(pcszP1, &hpf1, TRUE))
goto ERROR_EXIT;
fUser1 = FALSE;
}
else
{
hpf1 = LOUSHORT(pcszP1);
Assert(hpf1 >= 0 && hpf1 < MAX_PHYSICAL_FILES);
Assert(di.physical[hpf1].fUsed);
fUser1 = TRUE;
}
if (!DioOpenLogical(pcszL1, &hlf1, usType))
goto ERROR_EXIT;
if (!DioGetUser(hlf2, bUser, sizeof(bUser)))
goto ERROR_EXIT;
if (!DioSetUser(hlf1, bUser, sizeof(bUser)))
goto ERROR_EXIT;
if (!DioGetFlags(hlf2, &fl))
goto ERROR_EXIT;
if (!DioSetFlags(hlf1, fl))
goto ERROR_EXIT;
if (!DioGetVersion(hlf2, &usVersion))
goto ERROR_EXIT;
if (!DioSetVersion(hlf1, usVersion))
goto ERROR_EXIT;
fResult = TRUE;
ERROR_EXIT:
if (hlf1 >= 0)
DioCloseLogical(hlf1);
if (!fUser1 && hpf1 >= 0)
DioClosePhysical(hpf1);
if (hlf2 >= 0)
DioCloseLogical(hlf2);
if (!fUser2 && hpf2 >= 0)
DioClosePhysical(hpf2);
return fResult;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------